home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / dev / src / adoc_src.lha / adoc-0.17 / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-20  |  18.4 KB  |  748 lines

  1. /*                                                               -*- C -*-
  2.  *  MAIN.C
  3.  *
  4.  *  (c)Copyright 1995 by Tobias Ferber,  All Rights Reserved
  5.  *
  6.  *  This file is part of ADOC.
  7.  *
  8.  *  ADOC is free software; you can redistribute it and/or modify
  9.  *  it under the terms of the GNU General Public License as published
  10.  *  by the Free Software Foundation; either version 1 of the License,
  11.  *  or (at your option) any later version.
  12.  *
  13.  *  ADOC is distributed in the hope that it will be useful,
  14.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  *  GNU General Public License for more details.
  17.  *
  18.  *  You should have received a copy of the GNU General Public License
  19.  *  along with this program; see the file COPYING.  If not, write to
  20.  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23. /* $VER: $Id: main.c,v 1.8 1995/03/20 18:43:59 tf Exp $ */
  24.  
  25. #include <ctype.h>
  26. #include <string.h>
  27. #include <stdlib.h>
  28. #include <stdarg.h>
  29. #include <time.h>
  30. #include <stdio.h>
  31.  
  32. #include "adoc.h"
  33. #include "flist.h"
  34. #include "libfun.h"
  35. #include "mactab.h"
  36. #include "version.h"
  37. #include "debug.h"
  38.  
  39. /*@*/
  40.  
  41. /* local variables */
  42. static char *whoami;
  43. static FILE *ferr;
  44.  
  45. /* function to export `ferr' to the scanner */
  46. FILE *get_ferr(void) { return ferr; }
  47.  
  48. /**/
  49.  
  50. static void echo(const char *fmt, ...)
  51. {
  52.   va_list argp;
  53.   va_start(argp,fmt);
  54.  
  55.   fprintf(stderr,"%s: ",whoami);
  56.   vfprintf(stderr,(char *)fmt,argp);
  57.   fprintf(stderr,"\n");
  58.   fflush(stderr);
  59.  
  60.   va_end(argp);
  61. }
  62.  
  63.  
  64. /**/
  65.  
  66. int main(int argc, char *argv[])
  67. {
  68.   int err= 0; /* return code */
  69.  
  70.   char *infile     = (char *)0;
  71.   char *outfile    = (char *)0;      /* --output-file       */
  72.   char *errfile    = (char *)0;      /* --error-file        */
  73.   char *headerfile = (char *)0;      /* --texi-header-file  */
  74.   char *yank_type  = "*";            /* --yank-type         */
  75.   char *body_env   = "smallexample"; /* -B<environment>     */
  76.  
  77.   int page_width         = 80;       /* --page-width        */
  78.   int tabsize            = 8;        /* --tab-size          */
  79.   int tabs_to_spaces     = 0;        /* --tabs-to-spaces    */
  80.   int output_type        = 1;        /* --output-type       */
  81.   int table_of_contents  = 0;        /* --table-of-contents */
  82.   int sort_entries       = 0;        /* --sort-entries      */
  83.   int texi_flags         = TEXI_CREATE_HEADER | TEXI_PARSE_REFERENCES | TEXI_ITEMIZE_REFERENCES;
  84.   int adoc_flags         = ADOC_FORM_FEEDS;
  85.   int warn_mask          = WARN_NORMAL;
  86.  
  87.   /* handles for the macro tables */
  88.  
  89.   int texi_macros;
  90.   int body_macros;
  91.  
  92. #ifdef _DCC /* Dice */
  93.   expand_args(argc,argv, &argc,&argv);
  94. #endif /* _DCC */
  95.  
  96.   /* filenames on MS-DOG systems look very ugly: all uppercase and
  97.    *  backslashes.  Perform some cosmetics */
  98.  
  99. #ifdef __MSDOS__
  100.   whoami= "adoc";
  101.  
  102. #else
  103.   whoami= argv[0];
  104.  
  105. #endif /*__MSDOS__*/
  106.  
  107.  
  108.   /* set the debugging defaults */
  109.   D(bug_init(0,stdout));
  110.  
  111.   if(err == 0)
  112.   {
  113.     /* prepare the texinfo macro table */
  114.     texi_macros= mactab_new( 4+10 );
  115.  
  116.     if(texi_macros)
  117.     {
  118.       ; /* initialize macro table */
  119.     }
  120.     else err= 1;
  121.   }
  122.  
  123.   if(err == 0)
  124.   {
  125.     /* prepare the body-text macro table */
  126.     body_macros= mactab_new( 2 );
  127.  
  128.     if(body_macros)
  129.     {
  130.       ; /* initialize macro table */
  131.     }
  132.     else err= 2;
  133.   }
  134.  
  135.   if(err)
  136.     echo("error %d creating macro tables -- not enough memory?", err);
  137.  
  138.   else
  139.  
  140.   /* BEGIN scanning command line arguments */
  141.  
  142.   while( (--argc > 0) && (err <= 0) )
  143.   {
  144.     char *arg= *++argv;
  145.  
  146. #ifdef DEBUG
  147.     if(argc > 1)  { D(bug("examining command line argument `%s' ( `%s', ... ) [%d]", argv[0], argv[1], argc-1)); }
  148.     else          { D(bug("examining command line argument `%s' ( ) [%d]", argv[0], argc-1)); }
  149. #endif /* DEBUG */
  150.  
  151.     if(*arg=='-')
  152.     {
  153.       /* remember the original command-line option string */
  154.       char *opt= arg;
  155.  
  156.       if(arg[1]=='-')
  157.         arg= convert_args(*argv);
  158.  
  159.       switch(*++arg)
  160.       {
  161.  
  162. /*-0*/  case '0':
  163.           output_type= 0;
  164.           break;
  165.  
  166. /*-1*/  case '1':
  167.           output_type= 1;
  168.           break;
  169.  
  170. /*-2*/  case '2':
  171.           output_type= 2;
  172.           sort_entries= 1;
  173.           tabs_to_spaces= 1;
  174.           break;
  175.  
  176. /*-b*/  case 'b':
  177.           texi_flags |= TEXI_TABLE_FUNCTIONS;
  178.           break;
  179.  
  180. /*-B*/  case 'B':
  181.           if(arg[1]) ++arg;
  182.           else arg= (--argc > 0) ? *(++argv) : (char *)0;
  183.  
  184.           if(arg && *arg)
  185.           {
  186.             body_env= arg;
  187.           }
  188.           else
  189.           {
  190.             echo("missing texinfo body text environment after %s option",opt);
  191.             err= 1;
  192.           }
  193.           break;
  194.  
  195. /*-c*/  case 'c':
  196.           err= mactab_add(body_macros, "\\*", "/*", "*\\", "*/", (char *)0);
  197.  
  198.           if(err)
  199.             echo("error %d adding comment convertion macros",err);
  200.           break;
  201.  
  202. /*-d*/  case 'd':
  203.  
  204. #ifdef DEBUG
  205.  
  206.           if(arg[1]) { D(bug_level= atoi( &(arg[1]) )); }
  207.           else       { D(bug_level= 1); }
  208.  
  209. #else /* !DEBUG */
  210.           echo("not compiled w/ -DDEBUG.  No debug information available -- Sorry");
  211.           /* no error */
  212.  
  213. #endif /* DEBUG */
  214.  
  215.           break;
  216.  
  217.  
  218. /*-D*/  case 'D':
  219.           if(arg[1] && --argc > 0)
  220.           {
  221.             char *lhs= &arg[1];
  222.             char *rhs= *(++argv);
  223.  
  224.             err= mactab_add(texi_macros, lhs, rhs, (char *)0);
  225.  
  226.             if(err)
  227.               echo("error adding texinfo macro `%s' = `%s'", lhs, rhs);
  228.           }
  229.           else
  230.           {
  231.             echo("missing macro %s after `%s' option",(arg[1] ? "value":"name"),opt);
  232.             err= 1;
  233.           }
  234.           break;
  235.  
  236. /*-E*/  case 'E':
  237.           if(arg[1]) ++arg;
  238.           else arg= (--argc > 0) ? *(++argv) : (char *)0;
  239.  
  240.           if(arg && *arg)
  241.           {
  242.             if(errfile)
  243.             {
  244.               echo("warning: option `%s' has already been seen", opt);
  245.               D(bug("%s \"%s\" superseeds -E \"%s\"", opt, arg, errfile));
  246.             }
  247.  
  248.             /*errfile= strcmp(arg,"-") ? arg : (char *)0;*/
  249.             errfile= arg;
  250.           }
  251.           else /* !(arg && *arg) */
  252.           {
  253.             echo("missing filename after `%s' option", opt);
  254.             err= 1;
  255.           }
  256.           break;
  257.  
  258. /*-f*/  case 'f':
  259.           if(arg[1])
  260.           {
  261.             while(*++arg) switch(*arg)
  262.             {
  263.               case 'f':
  264.                 adoc_flags |= ADOC_FORM_FEEDS;
  265.                 texi_flags |= TEXI_FUNCTION_NEWPAGE;
  266.                 break;
  267.  
  268.               default:
  269.                 echo("unknown paging option: `%s'",opt);
  270.                 break;
  271.             }
  272.           }
  273.           else /* !arg[1] */
  274.           {
  275.             adoc_flags &= ~ADOC_FORM_FEEDS;
  276.             texi_flags &= ~TEXI_FUNCTION_NEWPAGE;
  277.           }
  278.           break;
  279.  
  280. /*-g*/  case 'g':
  281.           if(arg[1])
  282.           {
  283.             while(*++arg) switch(*arg)
  284.             {
  285.               case 's':
  286.                 texi_flags |= TEXI_GROUP_SECTIONS;
  287.                 break;
  288.  
  289.               default:
  290.                 echo("unknown grouping option: `%s'",opt);
  291.                 err= 1;
  292.                 break;
  293.             }
  294.           }
  295.           else texi_flags &= ~TEXI_GROUP_SECTIONS;
  296.           break;
  297.  
  298. /*-H*/  case 'H':
  299.           if(arg[1]) ++arg;
  300.           else arg= (--argc > 0) ? *(++argv) : (char *)0;
  301.  
  302.           if(arg && *arg)
  303.           {
  304.             if(headerfile)
  305.             {
  306.               echo("warning: option `%s' has already been seen", opt);
  307.               D(bug("%s \"%s\" superseeds -H \"%s\"", opt, arg, headerfile));
  308.             }
  309.  
  310.             headerfile= arg;
  311.           }
  312.           else /* !(arg && *arg) */
  313.           {
  314.             echo("missing texinfo header filename after `%s' option", opt);
  315.             err= 1;
  316.           }
  317.           break;
  318.  
  319. /*-h*/  case 'h':
  320.           printf("usage: %s [options] [-o outfile] [@ listfile] [infiles...]\n\n", whoami);
  321.           display_args();
  322.           err= -1;    /* negative means exit w/o error */
  323.           break;
  324.  
  325. /*-I*/  case 'I':
  326.           table_of_contents= 1;
  327.           break;
  328.  
  329. /*-i*/  case 'i':
  330.           yank_type= "i";
  331.           break;
  332.  
  333. /*-l*/  case 'l':
  334.           if(arg[1]) ++arg;
  335.           else arg= (--argc > 0) ? *(++argv) : (char *)0;
  336.  
  337.           if(arg && *arg)
  338.           {
  339.             page_width= atoi(arg);
  340.  
  341.             if(page_width < 1)
  342.             {
  343.               echo("illegal page width: `%s'  (must be > 0)", arg);
  344.               err= 1;
  345.             }
  346.           }
  347.           else /* !(arg && *arg) */
  348.           {
  349.             echo("missing page width after `%s' option", opt);
  350.             err= 1;
  351.           }
  352.           break;
  353.  
  354. /*-M*/  case 'M':
  355.           if(arg[1] && --argc > 0)
  356.           {
  357.             char *lhs= &arg[1];
  358.             char *rhs= *(++argv);
  359.  
  360.             err= mactab_add(body_macros, lhs, rhs, (char *)0);
  361.  
  362.             if(err)
  363.               echo("error adding body macro `%s' -> `%s'", lhs, rhs);
  364.           }
  365.           else
  366.           {
  367.             echo("missing macro %s after `%s' option",(arg[1] ? "value":"name"),opt);
  368.             err= 1;
  369.           }
  370.           break;
  371.  
  372. /*-n*/  case 'n':
  373.           output_type= 0;
  374.           break;
  375.  
  376. /*-o*/  case 'o':
  377.           if(arg[1])
  378.           {
  379.             output_type= ( isdigit(arg[1]) ? atoi(&arg[1])
  380.                                            : strarg(&arg[1], "autodoc", "texinfo", "") );
  381.  
  382.             if( (output_type < 1) || (output_type > 2) )
  383.             {
  384.               echo("unknown output type: `%s'  (must be in [1..2])", &arg[1]);
  385.               err= 1;
  386.             }
  387.           }
  388.  
  389.           arg= (--argc > 0) ? *(++argv) : (char *)0L;
  390.  
  391.           if(arg && *arg)
  392.           {
  393.             if(outfile)
  394.               echo("warning: option `%s' has already been seen", opt);
  395.  
  396.             outfile= arg;
  397.           }
  398.           else /* !(arg && *arg) */
  399.           {
  400.             echo("missing filename after `%s' option", opt);
  401.             err= 1;
  402.           }
  403.           break;
  404.  
  405. /*-p*/  case 'p':
  406.           sort_entries= 0;
  407.           break;
  408.  
  409. /*-q*/  case 'q':
  410.           break;
  411.  
  412. /*-T*/  case 'T':
  413.           if(arg[1]) ++arg;
  414.           else arg= (--argc > 0) ? *(++argv) : (char *)0;
  415.  
  416.           if(arg && *arg)
  417.           {
  418.             tabs_to_spaces= 1;
  419.             tabsize= atoi(arg);
  420.  
  421.             if(tabsize < 1)
  422.             {
  423.               echo("illegal tab step: `%d'  (must be >= 1)", tabsize);
  424.               err= 1;
  425.             }
  426.           }
  427.           else /* !(arg && *arg) */
  428.           {
  429.             echo("missing tab size after `%s' option", opt);
  430.             err= 1;
  431.           }
  432.           break;
  433.  
  434. /*-t*/  case 't':
  435.           tabs_to_spaces= arg[1] ? atoi(&arg[1]) : 1;
  436.           break;
  437.  
  438. /*-U*/  case 'U':
  439.           if(arg[1]) ++arg;
  440.           else arg= (--argc > 0) ? *(++argv) : (char *)0;
  441.  
  442.           if(arg && *arg)
  443.           {
  444.             mactab_remove(texi_macros, arg, (char *)0);
  445.             mactab_remove(body_macros, arg, (char *)0);
  446.           }
  447.  
  448.           else /* !(arg && *arg) */
  449.           {
  450.             echo("missing macro after `%s' option", opt);
  451.             err= 1;
  452.           }
  453.           break;
  454.  
  455. /*-v*/  case 'v':
  456.           printf("ADOC Version " VERSION " (compiled " __DATE__ ", " __TIME__ ")\n"
  457.                  "(c)Copyright 1995 by Tobias Ferber,  All Rights Reserved\n" );
  458.           err= -1;
  459.           break;
  460.  
  461. /*-W*/  case 'W':
  462.           if(arg[1])
  463.           {
  464.             ++arg;
  465.  
  466.             if( isdigit(*arg) )
  467.               warn_mask |= atoi(arg);
  468.  
  469.             else switch( strarg(arg, "none",       /* 1 */
  470.                                      "arnings",    /* 2 */
  471.                                      "keywords",   /* 3 */
  472.                                      "absence",    /* 4 */
  473.                                      "all", "") )  /* 5 */
  474.             {
  475.               case 1:   warn_mask  = WARN_NONE;                 break;
  476.               case 2:   warn_mask |= WARN_NORMAL;               break;
  477.               case 3:   warn_mask |= WARN_UNKNOWN_KEYWORDS;     break;
  478.               case 4:   warn_mask |= WARN_MISSING_KEYWORDS;     break;
  479.               case 5:   warn_mask |= WARN_ALL;                  break;
  480.  
  481.               default:
  482.                 echo("unknown warning method: `%s'",opt);
  483.                 err= 1;
  484.                 break;
  485.             }
  486.           }
  487.           else warn_mask= WARN_NONE;
  488.           break;
  489.  
  490. /*-x*/  case 'x':
  491.           if(arg[1])
  492.           {
  493.             switch( strarg(++arg, "off",        /* 1 */
  494.                                   "on",         /* 2 */
  495.                                   "itemize",    /* 3 */
  496.                                   "", "") )     /* 4 */
  497.             {
  498.               case 1:   texi_flags &= ~TEXI_PARSE_REFERENCES;
  499.                         texi_flags &= ~TEXI_ITEMIZE_REFERENCES;   break;
  500.  
  501.               case 2:   texi_flags |=  TEXI_PARSE_REFERENCES;
  502.                         texi_flags &= ~TEXI_ITEMIZE_REFERENCES;   break;
  503.  
  504.               case 3:   texi_flags |=  TEXI_PARSE_REFERENCES;
  505.                         texi_flags |=  TEXI_ITEMIZE_REFERENCES;   break;
  506.  
  507.               default:
  508.                 echo("unknown reference handlig option: `%s'",opt);
  509.                 err= 1;
  510.                 break;
  511.             }
  512.           }
  513.           else texi_flags &= ~(TEXI_PARSE_REFERENCES | TEXI_ITEMIZE_REFERENCES);
  514.           break;
  515.  
  516. /*-y*/  case 'y':
  517.           if(arg[1]) ++arg;
  518.           else arg= (--argc > 0) ? *(++argv) : (char *)0L;
  519.  
  520.           if(arg && *arg)
  521.             yank_type= arg;
  522.  
  523.           else /* !(arg && *arg) */
  524.           {
  525.             echo("missing comment type string after `%s' option", opt);
  526.             err= 1;
  527.           }
  528.           break;
  529.  
  530. /*-z*/  case 'z':
  531.           texi_flags &= ~TEXI_CREATE_HEADER;
  532.           break;
  533.  
  534.           /*
  535.            *  The following options are ignored for compatibility
  536.            *  with Bill Koester's original version `autodoc' which
  537.            *  is part of C=ommodore's Native Developer Kit (NDK).
  538.            */
  539.  
  540. /*-C*/  case 'C':
  541. /*-F*/  case 'F':
  542. /*-s*/  case 's':
  543. /*-a*/  case 'a':
  544. /*-r*/  case 'r':
  545. /*-w*/  case 'w':
  546.           echo("warning: option `%s' ignored for compatibility", opt);
  547.           break;
  548.  
  549. /*- */  case '\0':
  550.           if( (err= flist_addfile("")) )
  551.              echo("out of memory... hmmmmmmmmmpf!");
  552.            break;
  553.  
  554. /*??*/  default:
  555.           echo("unrecognized option `%s'", opt);
  556.           err= 1;
  557.           break;
  558.       }
  559.     }
  560.     else if(*arg=='@')
  561.     {
  562.       if(arg[1]) ++arg;
  563.       else arg= (--argc > 0) ? *(++argv) : (char *)0L;
  564.  
  565.       if(arg && *arg)
  566.       {
  567.         if( (err= flist_from_file(arg)) )
  568.           echo("out of memory... aaarrrrrrgggggghh!");
  569.       }
  570.       else /* !(arg && *arg) */
  571.       {
  572.         echo("missing filename after `%s'", *argv);
  573.         err= 1;
  574.       }
  575.     }
  576.     else /* *arg != '@' */
  577.     {
  578.       if(arg && *arg)
  579.       {
  580.         if( (err= flist_addfile(arg)) )
  581.           echo("out of memory... aaaiiiiiieeeeeeeee!");
  582.       }
  583.       else echo("internal problem parsing command line arguments: arg is empty");
  584.     }
  585.   }
  586.   /* END scanning command line arguments */
  587.   D(bug("command line argument parsing done"));
  588.  
  589.   if(err == 0)
  590.   {
  591.     /* prepare the error stream */
  592.  
  593.     if(errfile && *errfile)
  594.     {
  595.       D(bug("opening error stream `%s'",errfile));
  596.  
  597.       if( !(ferr= fopen(errfile,"w")) )
  598.       {
  599.         echo("could not write error messages to `%s'",errfile);
  600.         err= __LINE__;
  601.       }
  602.     }
  603.     else ferr= stderr;
  604.  
  605.     /* if no filename is given then read from stdin */
  606.  
  607.     if( !flist_getname() )
  608.       flist_addfile("");
  609.  
  610.  
  611.     /* read the input files (the scanner takes them from the flist queue) */
  612.  
  613.     D(bug("reading autodocs of type `%s'", yank_type));
  614.  
  615.     if(err == 0)
  616.       err= read_source(yank_type, warn_mask);
  617.  
  618.     if(err < 0)
  619.       err= -err;  /* I/O error */
  620.  
  621.     D(bug("disposing file list"));
  622.     flist_dispose();
  623.  
  624.     /*
  625.      */
  626.  
  627.     if( (err == 0) && (output_type > 0) )
  628.     {
  629.       FILE *fout;
  630.  
  631.       /* prepare the output file */
  632.  
  633.       if(outfile && *outfile)
  634.       {
  635.         D(bug("opening output stream `%s'",outfile));
  636.  
  637.         if(!(fout= fopen(outfile,"w")) )
  638.         {
  639.           echo("could not write to `%s'",outfile);
  640.           err= __LINE__;
  641.         }
  642.       }
  643.       else fout= stdout;
  644.  
  645.  
  646.       if( fout && (err==0) )
  647.       {
  648.         if(sort_entries)
  649.         {
  650.           D(bug("sorting entries"));
  651.           funsort();
  652.         }
  653.  
  654.         switch(output_type)
  655.         {
  656.           case 1: /* --autodoc */
  657.  
  658.             if(table_of_contents)
  659.             {
  660.               D(bug("writing table of contents"));
  661.               err= gen_autodoc_toc(fout);
  662.             }
  663.             if(err == 0)
  664.             {
  665.               D(bug("writing autodocs"));
  666.               err= gen_autodoc( fout, page_width, tabs_to_spaces ? tabsize : 0, adoc_flags, mactab(body_macros) );
  667.             }
  668.             break;
  669.  
  670.           case 2: /* --texinfo */
  671.             if(texi_flags & TEXI_CREATE_HEADER)
  672.             {
  673.               D(bug("creating texinfo header"));
  674.               err= gen_texinfo_header( fout, headerfile, mactab(texi_macros) );
  675.             }
  676.  
  677.             if(err == 0)
  678.             {
  679.               D(bug("adding texinfo body macros"));
  680.               err= mactab_add( body_macros,  "@",        "@@",
  681.                                              "{",        "@{",
  682.                                              "}",        "@}",
  683.                                           /* "...",      "@dots{}", */
  684.                                           /* "TeX",      "@TeX{}",  */
  685.                                              "e.g. ",    "e.g.@: ",
  686.                                              "E.g. ",    "E.g.@: ",
  687.                                              "i.e. ",    "i.e.@: ",
  688.                                              "I.e. ",    "I.e.@: ",   (char *)0 );
  689.             }
  690.  
  691.             if(err == 0)
  692.             {
  693.               D(bug("creating texinfo output"));
  694.               err+= gen_texinfo( fout, tabs_to_spaces ? tabsize : 0, texi_flags, body_env, mactab(body_macros) );
  695.             }
  696.  
  697.             if(err)
  698.               echo("error creating texinfo output");
  699.             break;
  700.  
  701.           default: /* --dry-run */
  702.             break;
  703.         }
  704.       }
  705.  
  706.       if(fout && (fout != stdout))
  707.         fclose(fout);
  708.     }
  709.  
  710.     D(bug("disposing libfun entries"));
  711.     funfree();
  712.   }
  713.  
  714. #ifdef DEBUG
  715.   mactab_debug(bug_stream);
  716. #endif
  717.  
  718.   D(bug("disposing macro tables"));
  719.   mactab_dispose(body_macros);
  720.   mactab_dispose(texi_macros);
  721.  
  722.   /*
  723.   */
  724.  
  725.   if(err > 0)
  726.   {
  727.     echo("[%s] *** Error %d", infile, err);
  728.     fprintf(ferr,"%s terminated abnormally (error %d)\n", whoami, err);
  729.   }
  730.  
  731.   D(bug("closing I/O streams"));
  732.  
  733.   if( ferr && (ferr != stderr) && (ferr != stdout) )
  734.     fclose(ferr);
  735.  
  736.   D(bug("exiting adoc returning %d (%s)", (err>0) ? 1:0, (err>0) ? "error":"success" ));
  737.   D(bug_exit());
  738.  
  739. #ifdef DEBUG
  740.  
  741.   if(bug_stream && (bug_stream != stdout))
  742.     fclose(bug_stream);
  743.  
  744. #endif /*DEBUG*/
  745.  
  746.   return (err > 0) ? 1:0;
  747. }
  748.